Formula Structure

Microsoft Visual Basic .NET with OneStream API and Member Scripts

All formulas and business rules run as compiled VB.NET code. In a VB.NET function or subroutine, calls are made to specific API functions that enable the rule writer to interact with the analytic engine.  Specific API functions are used to process member script expressions and create calculated values in the analytic data model.

Common Finance APIs that Use Member Scripts

Copy
api.Data.GetDataCell(“A#Cash”) 

This returns a single numeric cell value.

Copy
api.Data.GetDataCellEx(“A#Cash”) 

This returns a single numeric or text cell value.

Copy
api.Data.SetDataCell(“A#Cash”, 5.00, False) 

This saves and writes a single data cell value.

Copy
api.Data.Calculate(“A#Cash = A#Sales * 0.10”)

This saves multiple data cells as stored values.

Basic Dynamic Cell Calculation

The following examples return a single cell.

Calculate Current Ratio

Copy
Return api.Data.GetDataCell("A#15000:O#Top / A#22000:O#Top")

Formula Composition

Copy
VB.NET    Language Keyword(s)
Return

OneStream API Function  

Copy
api.Data.GetDataCell("Member Script”)

OneStream Member Script

Copy
A#15000:O#Top / A#22000:O#Top

TIP: When using a nested function (YearPrior(|POVTime|) in a GetDataCell call, you must enclose the function in square brackets []. This is necessary because GetDataCell and the functions use “(“and “)” as indicators of the start points and end points in the script. The inner functions must be wrapped in square brackets.
GetDataCell("S#[|!ScenarioActual_GRT!|]:T#[YearPrior1(|CVTime|)][Period(|CVTime|)]"):Name("PYR Var")

Basic Stored Calculation

The following examples calculate and store multiple cells.

Pull Prior Period Retained Earnings

Copy
api.Data.Calculate("A#28000 = A#28999:T#POVPrior1")

Formula Composition

Copy
Formula Composition
OneStream API    Function
api.Data.Calculate("Member Script”)

Member Script

Copy
A#28000=A#28999:T#POVPrior1

You can use formula variables in member scripts to significantly improve performance when the same formula is used for multiple members. When using formula variables, the formula text remains the same, so there is no need for continued parsing and evaluation.

Using variables can also improve performance if a member ID is used instead of a member name because the ID can also be used as the value in a formula variable. To use a formula variable in a member script, use a dollar sign $ instead of a pound sign # before the member name, and use the variable name after the dollar sign.

Example 1

Copy
api.Data.FormulaVariables.SetTextVariable(“variableAccount”, “8150”)
api.Data.Calculate(“A#8250=A$variableAccount * 10”)

Example 2

Copy
Dim acctMember As Member = api.Members.GetMember(DimType.Account.Id, “8150”)
api.Data.FormulaVariables.SetMemberVariable(“variableAccount”,acctMember)
api.Data.Calculate(“A#8250= A$variableAccount * 100”)

Example 3

Copy
Dim acctMember As Member = api.Members.GetMember(DimType.Account.Id, “8150”)
Dim acctId As Integer = acctMember.MemberId
api.Data.FormulaVariables.SetIntegerVariable(“myAccount”,acctId)
api.Data.Calculate(“A#8250 = A$myAccount * 1000”)